package cn.samler.diandi.api.validator;

import cn.samler.diandi.api.annotation.IsRole;
import cn.samler.diandi.api.model.io.request.user.UserRole;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List;


/**
 * 角色校验
 * @author samler
 */
public class RoleValidator implements ConstraintValidator<IsRole, String> {

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        List<String> role = new ArrayList<String>(){
            {
                this.add(UserRole.ROLE_EMPLOYER);   // 雇主
                this.add(UserRole.ROLE_SEEKER);     // 求职者
            }
        };

        return role.contains(s);
    }
}
